package com.maxmlr.music.admin.service.transfer;

import com.google.common.collect.Maps;
import com.maxmlr.music.admin.entity.Menu;
import com.maxmlr.music.admin.param.MenuParam;
import com.maxmlr.music.admin.param.TreeParam;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @ClassName MenuTransfer
 * @Description TODO
 * @Author maxiao
 * @Date 2020/6/15 下午2:51
 * @Version V1.0
 */
@Component
public class MenuTransfer {


    public MenuParam po2MenuParam(Menu menu) {
        MenuParam menuParam = new MenuParam();
        menuParam.setId(menu.getId());
        menuParam.setParentId(menu.getParentId());
        menuParam.setName(menu.getName());
        menuParam.setParentName("");
        menuParam.setUrl(menu.getUrl());
        menuParam.setPerms(menu.getPerms());
        menuParam.setType(menu.getType());
        menuParam.setIcon(menu.getIcon());
        menuParam.setOrderNum(menu.getOrderNum());
        menuParam.setCreateTime(menu.getCreateTime());
        menuParam.setUpdateTime(menu.getUpdateTime());
        return menuParam;
    }

    public TreeParam<Menu> po2TreeParam(Menu menu) {
        TreeParam<Menu> tree = new TreeParam<Menu>();
        tree.setId(menu.getId().toString());
        tree.setParentId(menu.getParentId().toString());
        tree.setText(menu.getName());
        Map<String, Object> attributes = Maps.newHashMap();
        attributes.put("url", menu.getUrl());
        attributes.put("icon", menu.getIcon());
        tree.setAttributes(attributes);
        return tree;
    }
}
